<template>
  <div class="history">
    <el-dialog v-model="useStore.isHistorySearch" width="min(90%,550px)" :show-close="true" center>
      <div style="margin-bottom:10px;width:100%;">
          <el-button @click="handleDel" type="info" size="large">清除历史搜索记录</el-button>
      </div>
      <el-scrollbar height="400px">
        <div
          v-show="useStore.Historys.length"
          class="historyContent"
          v-for="(item, index) in useStore.Historys"
          :key="index"
          @click="handleHistory(item.content)"
        >
          <p>{{item.content}}</p>
          <p>{{item.create_time}}</p>
        </div>
        <div v-show="!useStore.Historys.length" class="historyContent1">
          <el-empty description="历史记录，没有了" />
        </div>
      </el-scrollbar>
    </el-dialog>
  </div>
</template>
<script setup>
import { reactive,onMounted,watch } from "vue";
import { useHomeStore } from "@/stores/home";
import { useMenuStore } from "@/stores/menu";
const useStore = useHomeStore();
const useMenu = useMenuStore();
const data = reactive({
  history:useStore.Historys,
});
onMounted(()=>{

})
const handleDel = ()=>{
  if(useStore.Historys.length){
    ElMessageBox.confirm("您确定要清除历史记录吗？", "清除历史记录", {
    confirmButtonText: "确认",
    cancelButtonText: "取消",
    center: true,
    confirmButtonClass:"btnClass",
    cancelButtonClass:"btnClass"
  })
    .then(() => {
      localStorage.removeItem('pandaHistory')
      useStore.Historys = []
      ElMessage({
        showClose: true,
        message: '清除历史记录成功',
        type: "success",
      });
    })
  }else{
    ElMessage({
        showClose: true,
        message: '没有历史记录可清',
        type: "error",
    });
  }
   
}
const handleHistory = (content)=>{
   window.open(
        `${useMenu.activatedEngine.url}${content}`,
        useMenu.target_blank ? "_blank" : "_self"
    )
}
</script>
<style lang="less" scoped>
/deep/ .el-dialog{
  border-radius: 12px !important;
}
.historyContent {
  width: 100%;
  height: 1.7rem;
  border-radius: 5px;
  display: flex;
  justify-content: space-between;
  cursor: pointer;
  p {
    display: flex;
    align-items: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    word-break: normal;
  }
  p:nth-child(1) {
    padding-left: 10px;
    width: 70%;
  }
  p:nth-child(2) {
    box-sizing: border-box;
    padding-right: 10px;
    font-size:  10px;
  }
}
.historyContent:hover{
  background-color: #000;
  color: #fff;
}
.historyContent1{
  width: 100%;
  height: 400px;
  display: flex;
  justify-content: center;
  align-items: center;
}
/deep/ .el-button{
  width: 100%;
}
</style>
<style>
.el-message-box {
  border-radius: 10px !important;
}
.btnClass {
  z-index: 1;
  position: relative;
  font-size: 14px;
  font-family: inherit;
  color: white;
  padding: 0.5em 1em;
  outline: none;
  border: none;
  background-color: hsl(236, 32%, 26%);
  overflow: hidden;
  transition: color 0.4s ease-in-out;
}

.btnClass::before {
  content: '';
  z-index: -1;
  position: absolute;
  top: 50%;
  left: 50%;
  width: 1em;
  height: 1em;
  border-radius: 50%;
  background-color: #3cefff;
  transform-origin: center;
  transform: translate3d(-50%, -50%, 0) scale3d(0, 0, 0);
  transition: transform 0.45s ease-in-out;
}

.btnClass:hover {
  cursor: pointer;
  color: #161616;
}

.btnClass:hover::before {
  transform: translate3d(-50%, -50%, 0) scale3d(15, 15, 15);
}

  .btnClass{
    background-color: black !important;
  }
  .btnClass span{
    color: #fff;
  }
  .btnClass span:hover{
    color: #161616 !important;
  }
</style>